#ifndef SEGMENTATOR_H
#define SEGMENTATOR_H
#define NODEBUG

#include <utility>
#include <queue>

#include "WordsLine.h"
#include "PamImage.h"
#include "io.h"

using namespace std;

struct WordSeperation{
    int xPosition;
    int runLength;
};

struct ImageHistogram
{
    long *horizontal;
    long *vertical;
};

struct ConnectedComponentDescription{
  long left;
  long right;
};

struct AStarPixel{
    int xPosition;
    int yPosition;
    double gScore;
    double hScore;
    double fScore;
    bool isOpen;
    bool isClosed;
    bool isBlack;
    AStarPixel* previousPixel;
};

//extracts the line image from the document
void ExtractLineImagesFromDocument(PamImage* document, vector<WordsLine>* lines);
void ExtractLineImageFromDocument(PamImage* document, WordsLine* line);

//adds word objects to the line, setting the coordinates using our own algoritm
void DetermineWordPositions(WordsLine* line);
void DetermineWordPositions(vector<WordsLine>* lines);

//sets the images of the words by using the word coordinates to extract the image from the line image
void ExtractWordImages(WordsLine* line);
void ExtractWordImages(vector<WordsLine>* lines);

void RemoveBelowLine(PamImage* image, int* line);
void RemoveAboveLine(PamImage* image, int* line);
PamImage* DrawLine(PamImage* image, int* line);
int* ToYArray(int width, AStarPixel* line);
int* GetSeperationLine(PamImage* image, int linePosition);
double GetHeuristicDistance(AStarPixel* first, AStarPixel* second);
int determineThresholdValue(PamImage* image);
ImageHistogram* makeHistogram(PamImage* image);
PamImage Clip(PamImage& image);
vector<WordSeperation*> getSeperations(WordsLine* line);
void SetLinePositions(WordsLine* line);
int ScoreBaseAndXPosition(long* values, long avarage, int xPosition, int basePosition, int height);

//statistic fucntions;
double getFscore(vector< double> histogram, size_t lastoffirstclass);
double sum(vector< double> vector);
double mean(vector< double> vector);
double variance(vector< double> vector);
#endif
